package com.chainshop.controller;

import javax.servlet.http.HttpServletResponse;

import com.chainshop.common.core.domain.pojo.Employees;
import com.chainshop.common.utils.poi.ExcelUtil;

import com.chainshop.service.IEmployeesService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chainshop.common.annotation.Log;
import com.chainshop.common.core.controller.BaseController;
import com.chainshop.common.core.domain.AjaxResult;
import com.chainshop.common.enums.BusinessType;
import com.chainshop.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 存储员工信息的Controller
 *
 * @author YEAH
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/system/employees")
public class EmployeesController extends BaseController
{
    @Autowired
    private IEmployeesService employeesService;

    /**
     * 查询存储员工信息的列表
     */
    @PreAuthorize("@ss.hasPermi('system:employees:list')")
    @GetMapping("/list")
    public TableDataInfo list(Employees employees)
    {
        startPage();
        List<Employees> list = employeesService.selectEmployeesList(employees);
        return getDataTable(list);
    }

    /**
     * 导出存储员工信息的列表
     */
    @PreAuthorize("@ss.hasPermi('system:employees:export')")
    @Log(title = "存储员工信息的", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Employees employees)
    {
        List<Employees> list = employeesService.selectEmployeesList(employees);
        ExcelUtil<Employees> util = new ExcelUtil<Employees>(Employees.class);
        util.exportExcel(response, list, "存储员工信息的数据");
    }

    /**
     * 获取存储员工信息的详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:employees:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(employeesService.selectEmployeesById(id));
    }

    /**
     * 新增存储员工信息的
     */
    @PreAuthorize("@ss.hasPermi('system:employees:add')")
    @Log(title = "存储员工信息的", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Employees employees)
    {
        return toAjax(employeesService.insertEmployees(employees));
    }

    /**
     * 修改存储员工信息的
     */
    @PreAuthorize("@ss.hasPermi('system:employees:edit')")
    @Log(title = "存储员工信息的", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Employees employees)
    {
        return toAjax(employeesService.updateEmployees(employees));
    }

    /**
     * 删除存储员工信息的
     */
    @PreAuthorize("@ss.hasPermi('system:employees:remove')")
    @Log(title = "存储员工信息的", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(employeesService.deleteEmployeesByIds(ids));
    }
}
